package cn.com.sueframe.dao.impl;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.apache.derby.client.am.SqlException;

import cn.com.sueframe.dao.BaseDao;
import cn.com.sueframe.dao.CompanyInfoDao;
import cn.com.sueframe.vo.CertificationVO;
import cn.com.sueframe.vo.CompanyVO;
import cn.com.sueframe.vo.GoodsVO;
import cn.com.sueframe.vo.OrderMenuVO;
import cn.com.sueframe.vo.PageVO;
import cn.com.sueframe.vo.PicVO;
import cn.com.sueframe.vo.TopPicVO;
import cn.com.sueframe.vo.UserVO;

public class CompanyInfoDaoImpl extends BaseDao implements CompanyInfoDao {
	/**
	 * 无参构造函数
	 * @author anmin
	 * Create 2013-5-27
	 */
	public CompanyInfoDaoImpl(){
		
	}
	/**
	 * 查找公司信息
	 * @return
	 * @throws SqlException
	 * Create 2013-3-26
	 * @throws SQLException 
	 */
	@SuppressWarnings("unchecked")
	public CompanyVO findCompanyInfo() throws SQLException{
		CompanyVO companyvo = new CompanyVO();
		CompanyVO companyVO = (CompanyVO)sqlMapClient.queryForObject("sueframe.findCompanyInfo",companyvo.getLanguage());
		return companyVO;
	}
	
	/**
	 * 查找商品种类信息
	 * @author anmin
	 * Create 2013-4-14
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<Object> findGoodsTypeInfo(String language)throws SQLException {
        List<Object> panelVOList = sqlMapClient.queryForList("sueframe.findGoodsTypeInfo", language);		
		return panelVOList;
	}
	/**
	 * 查找首页信息
	 * @author anmin
	 * Create 2013-4-14
	 */
	@Override
	public CompanyVO findHomeInfo(String language) throws SQLException {
		CompanyVO companyVO = (CompanyVO)sqlMapClient.queryForObject("sueframe.findHomeInfo",language);
		return companyVO;
	}
    /**
     * 查找商品
     * @author anmin
     * Create 2013-4-15
     */
	@SuppressWarnings("unchecked")
	@Override
	public List<Object> findGoods(PageVO pageVO) throws SQLException {
		List<Object> goodsList = sqlMapClient.queryForList("sueframe.findGoods", pageVO);
		return goodsList;
	}
	
	 /**
     * 查找商品记录条数
     * @author anmin
     * Create 2013-4-22
     */
	@SuppressWarnings("unchecked")
	@Override
	public Integer findGoodsCount(PageVO pageVO) throws SQLException {
		Integer count = (Integer)sqlMapClient.queryForObject("sueframe.findGoodsCount", pageVO);
		return count;
	}
	 /**
     * 查找单个产品信息
     * @author anmin
     * Create 2013-5-2
     */
	@Override
	public GoodsVO findSingleGoods(GoodsVO goodsVO) throws SQLException {
		Object goodsObj = sqlMapClient.queryForObject("sueframe.findSingleGoods", goodsVO);
		if(goodsObj != null){
			return (GoodsVO)goodsObj;
		}
		return null;
	}
	/**
	  * 保存用户信息
	  * @author anmin
	  * @return
	  * Created 2013-5-7
	  */
	@Override
	public void saveUserInfo(UserVO userVO) throws SQLException {
		sqlMapClient.insert("sueframe.saveUserInfo", userVO);
	}
    /*
     * (non-Javadoc)
     * @see cn.com.sueframe.dao.CompanyInfoDao#checkUseEmail(cn.com.sueframe.vo.UserVO)
     */
	@Override
	public String checkUseEmail(UserVO userVO) throws SQLException {
		String countStr = (String)sqlMapClient.queryForObject("sueframe.checkUseEmail", userVO);
		return countStr;
	
    }
    /*
     * (non-Javadoc)
     * @see cn.com.sueframe.dao.CompanyInfoDao#checkUserInfo(cn.com.sueframe.vo.UserVO)
     */
	@Override
	public String checkUserInfo(UserVO userVO) throws SQLException {
		String countStr = (String)sqlMapClient.queryForObject("sueframe.checkUserInfo", userVO);
		return countStr;
	}
   /*
    * (non-Javadoc)
    * @see cn.com.sueframe.dao.CompanyInfoDao#findUserNo(java.util.Map)
    */
	@Override
	public String findUserNo(Map<String, String> userInfoMap)throws SQLException {
		String userNo = "";
		userNo = (String)sqlMapClient.queryForObject("sueframe.findUserNo", userInfoMap);
		userNo = userNo == null ? "" : userNo;
		return userNo;
	}
	/*
	 * (non-Javadoc)
	 * @see cn.com.sueframe.dao.CompanyInfoDao#addGoodsToCart(cn.com.sueframe.vo.GoodsVO)
	 */
	@Override
	public void addGoodsToCart(GoodsVO goodsVO) throws SQLException {
		sqlMapClient.insert("sueframe.addGoodsToCart", goodsVO);		
	}
	/*
	 * (non-Javadoc)
	 * @see cn.com.sueframe.dao.CompanyInfoDao#isGoodsExistsInCart(java.lang.String)
	 */
	@Override
	public Integer isGoodsExistsInCart(Map<String,String> isExistsCond) throws SQLException {
		Integer isGoodsExistsFlag = 0;
		isGoodsExistsFlag = (Integer)sqlMapClient.queryForObject("sueframe.isGoodsExistsInCart", isExistsCond);
		return isGoodsExistsFlag;
	}
	/*
	 * (non-Javadoc)
	 * @see cn.com.sueframe.dao.CompanyInfoDao#updateGoodsCountFromCart(java.lang.String)
	 */
	@Override
	public void updateGoodsCountFromCart(Map<String,String> goodsInfo) throws SQLException {
		sqlMapClient.update("sueframe.updateGoodsCountFromCart", goodsInfo);
	}
	/*
	 * (non-Javadoc)
	 * @see cn.com.sueframe.dao.CompanyInfoDao#findGoodsFromCart(cn.com.sueframe.vo.PageVO)
	 */
	@SuppressWarnings(value="unchecked")
	public List<Object> findGoodsFromCart(PageVO page)throws SQLException{
		return (List<Object>)sqlMapClient.queryForList("sueframe.findGoodsFromCart", page);
	}
	/*
	 * (non-Javadoc)
	 * @see cn.com.sueframe.dao.CompanyInfoDao#findGoodsFromCartCount(cn.com.sueframe.vo.PageVO)
	 */
	@Override
	public Integer findGoodsFromCartCount(PageVO page) throws SQLException {
		return (Integer)sqlMapClient.queryForObject("sueframe.findGoodsFromCartCount", page);
	}
	/*
	 * (non-Javadoc)
	 * @see cn.com.sueframe.dao.CompanyInfoDao#saveGoodsCountToCart(cn.com.sueframe.vo.GoodsVO)
	 */
	@Override
	public void saveGoodsCountToCart(GoodsVO goodsVO) throws SQLException {
		sqlMapClient.update("sueframe.saveGoodsCountToCart", goodsVO);
	}
    /*
     * (non-Javadoc)
     * @see cn.com.sueframe.dao.CompanyInfoDao#findRemainGoods(cn.com.sueframe.vo.GoodsVO)
     */	
	@Override
	public String findRemainGoods(GoodsVO goodsVO) throws SQLException {
		Object goodsRemainCount = sqlMapClient.queryForObject("sueframe.findRemainGoods", goodsVO);
		goodsRemainCount = goodsRemainCount == null ? "0" : goodsRemainCount;
		return goodsRemainCount + "";
	}
	/*
	 * (non-Javadoc)
	 * @see cn.com.sueframe.dao.CompanyInfoDao#caculateTotalPrice(java.lang.String)
	 */
	@Override
	public String caculateTotalPrice(String userNo) throws SQLException {
		Object totalPriceObj = sqlMapClient.queryForObject("sueframe.caculateTotalPrice", userNo);
		totalPriceObj = totalPriceObj == null ? "0.00" : totalPriceObj; 
		return totalPriceObj + "";
	}
	/*
	 * (non-Javadoc)
	 * @see cn.com.sueframe.dao.CompanyInfoDao#reduceGoodsFromCartOneByOne(java.util.Map)
	 */
	@Override
	public void reduceGoodsFromCartOneByOne(Map<String, String> goodsInfo)throws SQLException {
		sqlMapClient.update("sueframe.reduceGoodsFromCartOneByOne", goodsInfo);
	}
	/*
	 * (non-Javadoc)
	 * @see cn.com.sueframe.dao.CompanyInfoDao#deleteGoodsFromCart(java.util.Map)
	 */
	@Override
	public void deleteGoodsFromCart(Map<String, String> goodsInfo)throws SQLException {
		sqlMapClient.delete("sueframe.deleteGoodsFromCart", goodsInfo);
	}
	/*
	 * (non-Javadoc)
	 * @see cn.com.sueframe.dao.CompanyInfoDao#saveOrderInfo(cn.com.sueframe.vo.OrderMenuVO)
	 */
	@Override
	public void saveOrderInfo(OrderMenuVO orderMenuVO) throws SQLException {
		sqlMapClient.insert("sueframe.saveOrderInfo", orderMenuVO);
	}
	/*
	 * (non-Javadoc)
	 * @see cn.com.sueframe.dao.CompanyInfoDao#updateGoodsCart4OrderMenu(java.util.Map)
	 */
	@Override
	public void updateGoodsCart4OrderMenu(Map<String, String> goodsCartInfo)throws SQLException {
		sqlMapClient.update("sueframe.updateGoodsCart4OrderMenu", goodsCartInfo);
	}
	/*
	 * (non-Javadoc)
	 * @see cn.com.sueframe.dao.CompanyInfoDao#findOrderInfo(java.lang.String)
	 */
	@Override
	public OrderMenuVO findOrderInfo(String id) throws SQLException {
		Object orderMenuObj = sqlMapClient.queryForObject("sueframe.findOrderInfo", id);
		OrderMenuVO orderMenuVO = orderMenuObj == null ? null : (OrderMenuVO)orderMenuObj;
		return orderMenuVO;
	}
	/*
	 * (non-Javadoc)
	 * @see cn.com.sueframe.dao.CompanyInfoDao#findOrderInfoGrdData()
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<Object> findOrderInfoGrdData(PageVO pageVO) throws SQLException {
		List<Object> goodsVOList = sqlMapClient.queryForList("sueframe.findOrderInfoGrdData",pageVO);
		return goodsVOList;
	}
	/*
	 * (non-Javadoc)
	 * @see cn.com.sueframe.dao.CompanyInfoDao#findOrderInfoGrdDataCount(cn.com.sueframe.vo.PageVO)
	 */
	@Override
	public Integer findOrderInfoGrdDataCount(PageVO pageVO)throws SQLException {
		Integer orderInforDataCount = (Integer)sqlMapClient.queryForObject("sueframe.findOrderInfoGrdDataCount", pageVO);
		return orderInforDataCount;
	}
	/*
	 * (non-Javadoc)
	 * @see cn.com.sueframe.dao.CompanyInfoDao#findGoodsIdFromCart(java.lang.String)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<String> findGoodsIdFromCart(String userNo) throws SQLException {
		return (List<String>)sqlMapClient.queryForList("sueframe.findGoodsIdFromCart", userNo);
	}
	/*
	 * (non-Javadoc)
	 * @see cn.com.sueframe.dao.CompanyInfoDao#findGoodsNos(cn.com.sueframe.vo.GoodsVO)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<Object> findGoodsNos(GoodsVO goodsVO) throws SQLException {
		return (List<Object>)sqlMapClient.queryForList("sueframe.findGoodsNos", goodsVO);
	}
	/*
	 * (non-Javadoc)
	 * @see cn.com.sueframe.dao.CompanyInfoDao#findGoodsByType(cn.com.sueframe.vo.PageVO)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<Object> findGoodsByType(PageVO pageVO) throws SQLException {
		return (List<Object>)sqlMapClient.queryForList("sueframe.findGoodsByType", pageVO);
	}
	/*
	 * (non-Javadoc)
	 * @see cn.com.sueframe.dao.CompanyInfoDao#findGoodsByCondition(cn.com.sueframe.vo.PageVO)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<Object> findGoodsByCondition(PageVO pageVO) throws SQLException {
		return (List<Object>)sqlMapClient.queryForList("sueframe.findGoodsByCondition", pageVO);
	}
	/*
	 * (non-Javadoc)
	 * @see cn.com.sueframe.dao.CompanyInfoDao#findGoodsByConditionCount(cn.com.sueframe.vo.PageVO)
	 */
	@Override
	public int findGoodsByConditionCount(PageVO pageVO) throws SQLException {
		Integer count = (Integer)sqlMapClient.queryForObject("sueframe.findGoodsByConditionCount", pageVO);
		return count;
	}
	/*
	 * (non-Javadoc)
	 * @see cn.com.sueframe.dao.CompanyInfoDao#findCertificationInfo(cn.com.sueframe.vo.PageVO)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<Object> findCertificationInfo(PageVO pageVO)throws SQLException {
		return (List<Object>)sqlMapClient.queryForList("sueframe.findCertificationInfo", pageVO);
	}
	
	/*
	 * (non-Javadoc)
	 * @see cn.com.sueframe.dao.CompanyInfoDao#findCertificationInfo(cn.com.sueframe.vo.PageVO)
	 */
	@Override
	public int findCertificationInfoCount(PageVO pageVO)throws SQLException {
		return (Integer)sqlMapClient.queryForObject("sueframe.findCertificationInfoCount", pageVO);
	}
	/*
	 * (non-Javadoc)
	 * @see cn.com.sueframe.dao.CompanyInfoDao#findSingleCertification(java.lang.String)
	 */
	@Override
	public CertificationVO findSingleCertification(String id)throws SQLException {
		return (CertificationVO)sqlMapClient.queryForObject("sueframe.findSingleCertification", id);
	}
    /*
     * (non-Javadoc)
     * @see cn.com.sueframe.dao.CompanyInfoDao#findAlbum(cn.com.sueframe.vo.PageVO)
     */	
	@SuppressWarnings("unchecked")
	@Override
	public List<Object> findAlbum(PageVO pageVO) throws SQLException {
		return (List<Object>)sqlMapClient.queryForList("sueframe.findAlbum", pageVO);
	}
	/*
	 * (non-Javadoc)
	 * @see cn.com.sueframe.dao.CompanyInfoDao#findAlbumCount()
	 */
	@Override
	public int findAlbumCount() throws SQLException {
		return (Integer)sqlMapClient.queryForObject("sueframe.findAlbumCount");
	}
	/*
	 * (non-Javadoc)
	 * @see cn.com.sueframe.dao.CompanyInfoDao#findPicList(cn.com.sueframe.vo.PageVO)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<Object> findPicList(PageVO pageVO) throws SQLException {
		return (List<Object>)sqlMapClient.queryForList("sueframe.findPicList", pageVO);
	}
	/*
	 * (non-Javadoc)
	 * @see cn.com.sueframe.dao.CompanyInfoDao#findPicListCount(cn.com.sueframe.vo.PageVO)
	 */
	@Override
	public int findPicListCount(PageVO pageVO) throws SQLException {
		return (Integer)sqlMapClient.queryForObject("sueframe.findPicListCount",pageVO);
	}
	/*
	 * (non-Javadoc)
	 * @see cn.com.sueframe.dao.CompanyInfoDao#findSinglePic(java.lang.String)
	 */
	@Override
	public PicVO findSinglePic(String picNo) throws SQLException {
		return (PicVO)sqlMapClient.queryForObject("sueframe.findSinglePic",picNo);
	}
	/*
	 * (non-Javadoc)
	 * @see cn.com.sueframe.dao.CompanyInfoDao#findPicNos(java.lang.String)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<Object> findPicNos(String albumNo) throws SQLException {
		return (List<Object>)sqlMapClient.queryForList("sueframe.findPicNos", albumNo);
	}
    /*
     * (non-Javadoc)
     * @see cn.com.sueframe.dao.CompanyInfoDao#findAnnonceContent()
     */
	@SuppressWarnings("unchecked")
	@Override
	public List<Object> findAnnonceContent() throws SQLException {
		return (List<Object>)sqlMapClient.queryForList("sueframe.findAnnonceContent");
	}
    /********************** anner ***************************************/
	
	/**
	 * 查找公司顶部图片
	 * 
	 * @author anner
	 * @return void
	 */
	@SuppressWarnings("unchecked")
	public List<TopPicVO> findTopPic(TopPicVO topPicVO)throws SQLException{
		List<TopPicVO> topPicVOList = sqlMapClient.queryForList("sueframe.findTopPic",topPicVO);
		return topPicVOList;
	}
	/*
	 * (non-Javadoc)
	 * @see cn.com.sueframe.dao.CompanyInfoDao#findGoodsByTypeCount(cn.com.sueframe.vo.PageVO)
	 */
	@Override
	public int findGoodsByTypeCount(PageVO pageVO) throws SQLException {
		Integer orderInforDataCount = (Integer)sqlMapClient.queryForObject("sueframe.findGoodsByTypeCount", pageVO);
		return orderInforDataCount;
	}
	/*
	 * (non-Javadoc)
	 * @see cn.com.sueframe.dao.CompanyInfoDao#findOnlineTool()
	 */
	@Override
	public String findOnlineTool() throws SQLException {
		return sqlMapClient.queryForObject("sueframe.findOnlineTool") + "";
	}
	
	
}
